import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:getx_scaffold/common/index.dart';
import 'package:oramemo/generated/assets.dart';
import '../model.dart';

class MessageCard extends StatelessWidget {
  final MessageModel message;
  final VoidCallback? onTap;

  const MessageCard({
    super.key,
    required this.message,
    this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        margin: EdgeInsets.symmetric(horizontal: 12.w, vertical: 4.5.h),
        decoration: BoxDecoration(
          color: const Color(0xFFFFFFFF),
          borderRadius: BorderRadius.circular(16.r),
        ),
        child: SizedBox(
          height: 80.h,
          child: Stack(
            children: [
              // 左侧时间区域
              Row(
                children: [
                  SizedBox(
                    width: 77.w,
                    height: 80.h,
                    child: Column(
                      mainAxisSize: MainAxisSize.max,
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Text(
                          message.time,
                          style: TextStyle(
                            color: const Color(0xFF333333),
                            fontSize: 14.sp,
                            fontFamily: 'Allerta',
                            fontWeight: FontWeight.w600,
                          ),
                        ),
                        Text(
                          message.period,
                          style: TextStyle(
                            color: Color(0xFF787979),
                            fontSize: 10.sp,
                            fontFamily: 'Allerta',
                            fontWeight: FontWeight.w400,
                          ),
                        ),
                      ],
                    ),
                  ),
                  // 分隔线
                  Container(
                    width: 1,
                    height: 80.h,
                    color: Color(0xFFB5BCCC),
                  ),
                  SizedBox(width: 20.w),
                  // 右侧内容区域
                  Expanded(
                    child: SizedBox(
                      height: 80.h,
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        mainAxisSize: MainAxisSize.max,
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Text(
                            message.title,
                            style: const TextStyle(
                              color: Colors.black,
                              fontSize: 14,
                              fontFamily: 'Allerta',
                              fontWeight: FontWeight.w400,
                            ),
                          ),
                          SizedBox(height: 7.h),
                          Text(
                            message.content,
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis,
                            style: const TextStyle(
                              color: Color(0xFF999999),
                              fontSize: 10,
                              fontFamily: 'Allerta',
                              fontWeight: FontWeight.w400,
                            ),
                          ),
                          SizedBox(height: 10.h),
                          // Row(
                          //   children: [
                          //     // 头像
                          //     Container(
                          //         width: 22,
                          //         height: 22,
                          //         decoration: ShapeDecoration(
                          //           color: Colors.grey.withOpacity(0.2),
                          //           shape: RoundedRectangleBorder(
                          //             borderRadius: BorderRadius.circular(20),
                          //           ),
                          //         ),
                          //         child: CachedNetworkImage(
                          //           imageUrl: message.avatar,
                          //           fit: BoxFit.cover,
                          //           placeholder: (context, url) =>
                          //               const CircularProgressIndicator(),
                          //           errorWidget: (context, url, error) =>
                          //               Image.asset(
                          //             Assets.imagesHead,
                          //             fit: BoxFit.cover,
                          //           ),
                          //         )),
                          //     const SizedBox(width: 6),
                          //     // 发送者名称
                          //     Text(
                          //       message.sender,
                          //       style: const TextStyle(
                          //         color: Color(0xFF777777),
                          //         fontSize: 14,
                          //         fontFamily: 'Allerta',
                          //         fontWeight: FontWeight.w400,
                          //       ),
                          //     ),
                          //   ],
                          // ),
                        ],
                      ),
                    ),
                  ),
                  SizedBox(width: 10.w),
                ],
              ),

              // 新消息提示点
              if (message.hasNew)
                Positioned(
                  right: 16,
                  top: 7,
                  child: Container(
                    width: 6,
                    height: 6,
                    decoration: const ShapeDecoration(
                      color: Color(0xFFFF3E3E),
                      shape: OvalBorder(),
                    ),
                  ),
                ),
            ],
          ),
        ),
      ),
    );
  }
}
